package org.ourgrid.broker.business.schedulerdata.executor;

import java.util.ArrayList;
import java.util.List;

import org.ourgrid.broker.business.schedulerdata.SchedulerData;
import org.ourgrid.broker.response.AcceptTransferResponseTO;
import org.ourgrid.common.internal.IResponseTO;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class AcceptTransferExecutor extends AbstractSchedulerDataExecutor {
	
	/**
	 * <ACCEPT_TRANSFER id='long' localFileName='String' destinationFileName='String' description='String' 
	 * senderContainerID='String' fileSize='long'/>
	 */
	public List<IResponseTO> execute(SchedulerData command) {
		List<IResponseTO> responses = new ArrayList<IResponseTO>();
		
		Document logDocFile = super.getXMl(command.getXml());
		
		Element acceptTransfer = logDocFile.getDocumentElement();
		
//		long id = Long.valueOf(acceptTransfer.getAttribute("id"));
//		String localFileName = acceptTransfer.getAttribute("localFileName");
//		String destinationFileName = acceptTransfer.getAttribute("destinationFileName");
//		String description = acceptTransfer.getAttribute("description");
//		String senderContainerID = acceptTransfer.getAttribute("senderContainerID");
//		long fileSize = Long.valueOf(acceptTransfer.getAttribute("fileSize"));

		long id = Long.valueOf(acceptTransfer.getAttribute("id"));
		String logicalFileName = acceptTransfer.getAttribute("logicalFileName");
		String description = acceptTransfer.getAttribute("description");
		String localFilePath = acceptTransfer.getAttribute("localFilePath");
		String senderContainerID = acceptTransfer.getAttribute("senderContainerID");
		long fileSize = Long.valueOf(acceptTransfer.getAttribute("fileSize"));		
		
		AcceptTransferResponseTO to = new AcceptTransferResponseTO();
		to.setDescription(description);
		to.setLocalFilePath(localFilePath);
		to.setFileSize(fileSize);
		to.setId(id);
		to.setLogicalFileName(logicalFileName);
		to.setSenderContainerID(senderContainerID);
		
		responses.add(to);
		
		return responses;
	}
}
